package com.bwie.demo.controller;

import com.bwie.demo.model.Consmetic;
import com.bwie.demo.model.Details;
import com.bwie.demo.service.ConsmeticService;
import com.bwie.demo.utils.PageResult;
import com.bwie.demo.utils.Result;
import com.bwie.demo.utils.Status;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @use ConsmeticController
 * @Author yp
 * @Date 2020-11-30-9:16
 */
@RestController
@CrossOrigin
@RequestMapping
public class ConsmeticController {

    /**
     * 注入化妆品业务层实现
     */
    @Autowired
    private ConsmeticService consmeticService;

    /**
     * 查询全部并分页
     * @param page 当前页
     * @param size 显示数
     * @param searchNap 对象
     * @return list
     */
    @PostMapping("/findAll/{page}/{size}")
    public Result findAll(@PathVariable int page, @PathVariable int size , @RequestBody Map searchNap){
        //调用查询的业务层方法并进行传参
        PageResult pages = consmeticService.findPage(page, size, searchNap);
        //放入返回值
        return new Result(true, Status.SUCCESS,"查询成功",pages);
    }

    /**
     * 根据详情id查询详情
     * @param id
     * @return 对象
     */
    @GetMapping("/findById/{id}")
    public Result findById(@PathVariable Integer id){
        Details byId = consmeticService.findById(id);
        return new Result(true, Status.SUCCESS,"查询成功",byId);
    }

    /**
     * 修改状态
     * @param id
     * @return void
     */
    @PostMapping("/updateRo/{id}")
    public Result updateRole(@PathVariable Integer id){
        //调用修改状态的方法
        consmeticService.update(id);
        return new Result(true, Status.SUCCESS,"修改成功");
    }
}
